import paddle
import numpy as np
from model_define import FallDetectionLSTM

def predict():
    # 1. 加载模型结构
    model = FallDetectionLSTM()
    
    # 2. 加载权重
    try:
        layer_state_dict = paddle.load("fall_detection_model.pdparams")
        model.set_state_dict(layer_state_dict)
        print("成功加载模型权重！")
    except:
        print("未找到权重文件，请先运行 train.py")
        return

    model.eval()

    # 3. 模拟一条实时传感器数据 (30帧, 4特征)
    # 模拟“跌倒”特征 (数值较大)
    fake_input = np.random.normal(loc=0.8, scale=0.2, size=(1, 30, 4))
    tensor_input = paddle.to_tensor(fake_input, dtype='float32')
    
    # 4. 推理
    result = model(tensor_input)
    prob_fall = result.numpy()[0][1] # 获取“跌倒(1)”的概率
    
    print(f"输入数据预测结果: 跌倒概率 = {prob_fall*100:.2f}%")
    if prob_fall > 0.5:
        print(">>> 判定结果：【跌倒】")
    else:
        print(">>> 判定结果：【正常】")

if __name__ == "__main__":
    predict()